import request from '@/utils/request';
import { baseurl } from './baseurl';
import { hasIsSw,isLianxiSite,isOnlyBinhai} from '../utils/utils';;
export interface getCoursewareParams {
  subject: any;
  name: string;
  uid: string;
}
export async function getCourseware(params: getCoursewareParams) {
  /* 学生获取课件 */
  const data = new FormData();
  // let subject = String(params.subject).replace('251','146').replace('253','146').replace('252','147').replace('254','147');
  data.append('subject', params.subject);
  data.append('name', params.name);
  data.append('uid', params.uid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }

  return request(`${baseurl}index/index/student_courseware`, {
    method: 'POST',
    data,
  });
}

export interface getMaterialeParams {
  subject: any;
  name: string;
  uid: string;
}
export async function getMateriale(params: getMaterialeParams) {
  /* 学生获取课件 */
  const data = new FormData();
  // let subject = String(params.subject).replace('251','146').replace('253','146').replace('252','147').replace('254','147');
  const subject = JSON.parse(localStorage.getItem('userinfo') || '{}').subject;
  data.append('subject',subject);
  data.append('name', params.name);
  data.append('uid', params.uid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }
  
  return request(`${baseurl}index/index/student_coursewares`, {
    method: 'POST',
    data,
  });
}

export interface collectCoursewareParams {
  collect: string;
  uid: string;
}
export async function collectCourseware(params: collectCoursewareParams) {
  /* 学生收藏课件 */
  const data = new FormData();
  data.append('collect', params.collect);
  data.append('uid', params.uid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }

  return request(`${baseurl}index/index/collect`, {
    method: 'POST',
    data,
  });
}

export interface getCollectCoursewareParams {
  uid: string;
  name: string;
}
export async function getCollectCourseware(params: getCollectCoursewareParams) {
  /* 学生获取收藏列表 */
  const data = new FormData();
  data.append('name', params.name);
  data.append('uid', params.uid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }

  return request(`${baseurl}index/index/collect_list`, {
    method: 'POST',
    data,
  });
}

export interface countLearnTimeParams {
  uid: string;
}
export async function countLearnTime(params: countLearnTimeParams) {
  /* 学生记录总学习时长 */
  const data = new FormData();
  data.append('uid', params.uid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }

  return request(`${baseurl}index/index/learn`, {
    method: 'POST',
    data,
  });
}

export interface coursewareTimeParams {
  uid: string;
  cid: string;
}
export async function coursewareTime(params: coursewareTimeParams) {
  /* 学生记录单个学习时长 */
  const data = new FormData();
  data.append('uid', params.uid);
  data.append('cid', params.cid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }

  return request(`${baseurl}index/index/courseware_time`, {
    method: 'POST',
    data,
  });
}
export interface countLearnNumParams {
  uid: string;
}
export async function countLearnNum(params: countLearnNumParams) {
  /* 学生记录单个学习时长 */
  const data = new FormData();
  data.append('uid', params.uid);
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }

  return request(`${baseurl}index/index/learn_num`, {
    method: 'POST',
    data,
  });
}
